package net.aaa.hotel.controller;

import net.aaa.hotel.dao.GustRoomDao;
import net.aaa.hotel.entity.GustRoom;
import net.aaa.hotel.entity.PageInfo;
import net.aaa.hotel.util.LayuiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/gustroom")
public class GustRoomController {
    final GustRoomDao gustRoomDao;

    @Autowired
    public GustRoomController(GustRoomDao gustRoomDao) {
        this.gustRoomDao = gustRoomDao;
    }

    @RequestMapping("show")
    @ResponseBody
    public LayuiTable showTable(PageInfo pageInfo){
        List<Map> roomTable = gustRoomDao.getAllRoomDaoByPage(pageInfo.getCurr(),pageInfo.getNums(), pageInfo.getCondition());
        int count = gustRoomDao.getCount(pageInfo.getCondition());
        LayuiTable table = new LayuiTable(count,roomTable);
        return table;
    }

    @RequestMapping("del")
    @ResponseBody
    public Integer delGustRoom(Integer id){
        int i = gustRoomDao.delGustRoomById(id);
        return i;
    }

    @RequestMapping("add")
    @ResponseBody
    public Integer addGustRoom(GustRoom gustRoom){
    //    System.out.println(gustRoom);
        int i = gustRoomDao.addGustRoom(gustRoom);
        return i;
    }

    @RequestMapping("upd")
    @ResponseBody
    public Integer updGustRoom(GustRoom gustRoom){
    //    System.out.println(gustRoom);
        int i = gustRoomDao.updGustRoom(gustRoom);
        return i;
    }
}
